[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
strcspn() Scan One String for Another
#include <string.h> Required for declarations only
size_t strcspn(string1,charset);
const char *string1; Source string
const char *charset; Character set
strcspn() searches 'string1' for the first occurrence of any of the
characters in 'charset'. The null character that terminates the
string is not considered in the search.
Returns: The index of the first character in 'string1' that
belongs to the set of characters found in 'charset'.
This value equals the length of the first substring
of 'string1' that is made up of characters not in
'charset'. If 'string1' begins with a character in
'charset', strcspn() returns 0.
Notes: strcspn() expects to operate on null-terminated
strings. No overflow checking is done when strings
are copied or appended.
-------------------------------- Example ---------------------------------
This example gets the length of the string up to the first delimiter
defined in the string 'delim' and then prints out the substring.
#include <string.h>
char string[35] = "Pick up the sword. Run for cover.";
char delim[4] = ".!?";
int rslt, x;
main()
{
rslt = strcspn(string,delim);
for (x = 0; x <= rslt; x++)
printf("%c",string[x]);
}
See Also:
strstr()
strspn()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson